﻿/**
*意向金转移
*/
Chenxin.UI.PayingForm = Chenxin.extend(Chenxin.UI.FormCommon, {
    actionUrl: '/service/logic/ShowListIntent.ashx',
    id: 'jqm_payingform',
    jqmWidth: 700,
    defBBtn: true,
    createForm: function() {
        return Chenxin.FormCommon.payingForm(this.id);
    },
    customerFormVal: function(json) {
        if (!json.GetedTime) {
            alert('收取时间不能为空！');
            return false;
        }
        if (parseFloat(json.PayMoney) == "0") {
            alert('转移金额必须大于0！');
            return false;
        }
        if (parseFloat(json.PayMoney) > parseFloat(json.GetedMoney)) {
            alert('此次转移金额不能超过已收金额！');
            return false;
        }
        else if (parseFloat(json.PayMoney) + parseFloat(json.DeliveredMoney) > parseFloat(json.GetedMoney)) {
            alert('此次转移金额与已转金额之和不能超过已收金额！');
            return false;
        }
        delete json.PayMoney;
        delete json.GetedMoney;
        delete json.DeliveredMoney;
        return true;
    },
    createComboList: function() {
        //门店
        var comboGetedDepartId = new Chenxin.UI.StructCombo({
            param: { op: 'getcontroldeparts' },
            containerId: '#GetedDepartId_pay',
            name: 'GetedDepartId',
            inModelType: 'all',
            txtModelName: 'GetedDepart',
            required: true,
            tbxWidth: 129,
            colNum: 4,
            hasPage: true,
            hasSearch: true,
            onSelected: function() {
                if (this.getValue() != this.defVal) {
                    comboGetedEmployeeId.loadUser(this.getValue());
                }
            },
            afterSetValue: function(newVal, oldVal) {
                if (newVal != this.defVal) {
                    comboGetedEmployeeId.loadUser(newVal);
                }
            }
        });
        //店长
        var comboGetedEmployeeId = new Chenxin.UI.RichModelTreeCombo({
            textBoxId: 'GetedEmployeeId_pay',
            containerId: '#GetedEmployeeId_pay',
            inModelType: 'all',
            txtModelName: 'GetedEmployee',
            required: false,
            singleSelect: true,
            name: 'GetedEmployeeId'
        });
        return [comboGetedDepartId, comboGetedEmployeeId];
    },
    initEvent: function() {
        var _this = this;
        this.findByName('AccountType').bind('click', function() {
            _this.findByName('GetedEmployeeId').required = this.value == '20' ? true : false;
            $('.tr_storelead')[this.value == '20' ? 'show' : 'hide']();
        });
    },
    initFormValidator: function() {
        //收取时间
        $('#' + this.id + '_GetedTime').formValidator({
            validatorgroup: this.id,
            onshow: "请输入收取时间",
            onfocus: "请输入收取时间",
            oncorrect: "填写正确"
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "请输入收取时间"
            },
            onerror: "请输入收取时间"
        });
        //金额
        $('#' + this.id + '_GetedMoney').formValidator({
            validatorgroup: this.id,
            onshow: "请输入金额！",
            onfocus: "金额为必输项",
            oncorrect: " "
        }).inputValidator({
            min: 1,
            empty: {
                leftempty: false,
                rightempty: false,
                emptyerror: "金额不能为空！"
            },
            onerror: "金额不能为空！"
        }).functionValidator({ //数字验证
            fun: function(val, elem) {
                val = Chenxin.Fn.fullToHalfChar(val);
                if (parseInt(val) < 0) {
                    return false;
                }
                else {
                    return val.isNum();
                }
            },
            onerror: "请输入非0数字"
        });
    },
    reset: function() {
        Chenxin.UI.PayingForm.superclass.reset.call(this);
    },
    initComponent: function() {
        Chenxin.UI.PayingForm.superclass.initComponent.call(this);
    }
});

    Chenxin.FormCommon.payingForm = function(formId) {// height:100px;overflow:auto;
    return '<table class="tbl_f"><tr><th style="width:100px;">意向编号：</th><td><input type="hidden" name="IntentionId"><input type="text" style="width: 160px;" class="inputbox_n fl" readonly="readonly" name="IntentionCode"></td><th style="width:100px;">业务员：</th><td><input type="text" readonly="readonly" name="LastEmployee" style="width:160px;" class="inputbox_n fl"></td></tr><tr><th>房东姓名：</th><td><input type="text" readonly="readonly" name="CustomerName_Sale" style="width:160px;" class="inputbox_n fl"></td><th>客户姓名：</th><td><input type="text" name="CustomerName_Buy" readonly="readonly" id="CustomerName_Buy" style="width:160px;" class="inputbox_n fl"></td></tr><tr><th>地址：</th><td colspan="3"><input type="text" name="HouseAddress" id="HouseAddress" readonly="readonly" style="width:455px;" class="inputbox_n fl"></td></tr><tr><th>总价：</th><td colspan="3"><input type="text" name="TotalPrice" id="TotalPrice"style="width:160px;" class="inputbox_n fl" readonly="readonly"></td></tr><tr><th>入账账户：</th><td colspan="3"><input type="radio" checked="checked" name="AccountType" value="10" id="chk_company_account"><label for="chk_company_account">公司账户</label><input type="radio" name="AccountType" value="20" id="chk_personal_account"><label for="chk_personal_account">授权账户</label></td></tr><tr><th>门店：</th><td colspan="3"><div class="SelectWrapSingle" style="z-index: 2; margin-right: 2px;" id="GetedDepartId_pay"></div></td></tr><tr class="tr_storelead" style="display:none;"><th>店长：</th><td colspan="3"><input type="text" style="width: 160px;" class="inputbox_n fl" id="GetedEmployeeId_pay" readonly="readonly"></td></tr><tr><th>已收总金额</th><td><input class="inputbox_n fl" type="text" id="GetedMoney" readonly="readonly" name="GetedMoney" style="width:160px"/></td><th>已转总金额</th><td><input class="inputbox_n fl" type="text" id="Text2" name="DeliveredMoney"  style="width:160px" readonly="readonly"/></td></tr><tr><th>本次转移金额：</th><td colspan="3"><input type="text" name="PayMoney" id="' + formId + '_GetedMoney" style="width:160px;" class="inputbox_n fl"/><div style="float: left; margin-left: 5px; width:90px;height: 26px; line-height: 26px; text-align: left;" id="' + formId + '_GetedMoneyTip"></div></td></tr><tr><th>转移时间：</th><td colspan="3"><input type="text" style="width: 160px;" onclick="WdatePicker({position:{left:this.getBoundingClientRect().left+1,top:this.getBoundingClientRect().top+22}});" readonly="readonly" id="' + formId + '_GetedTime" class="inputbox_n fl" name="GetedTime"></td></tr><tr><th><span >转定/房款：</span></th><td  colspan="3"><input type="radio" value="10" name="PayTo" checked="checked"/>定金<input type="radio" value="20" name="PayTo" />房款<input type="radio" value="30" name="PayTo" />退还客户</td></tr><tr><th>公司代保管：</th><td  colspan="3"><input type="radio" name="bCustody" value="10"/>是<input type="radio" name="bCustody" value="0" checked="checked"/>否</td></tr></table>';
    }